perf: offset-sorted mmap reads + disk read concurrency limiter#204
Merged
perf: offset-sorted mmap reads + disk read concurrency limiter#204
Conversation
Two changes to fix 5-10s doc read tail latency: 1. Sort keys by data.bin offset before reading (datasilo get_many_timed). Turns random mmap page faults into sequential access, enabling kernel readahead and I/O request merging. At 109M records across multi-GB data.bin, random access causes page fault storms under concurrency. 2. Add 16-permit semaphore on the spawn_blocking doc read path (server.rs). Caps concurrent disk readers from 78 (observed in prod) to 16. Excess readers queue in async context (no thread consumed) instead of all doing simultaneous page faults. Prod data: 0.35% of disk fetches took 5-10s, 2.2% took 2.5-5s. Expected: sequential reads reduce per-batch latency; semaphore eliminates the I/O contention that amplifies individual read times. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_many_timedkeys by data.bin offset before reading — turns random mmap page faults into sequential access with kernel readaheadtokio::sync::Semaphoreon thespawn_blockingdoc read path — caps concurrent disk readers from 78 (observed) to 16, preventing I/O contention collapseProblem
Prod metrics show 0.35% of disk fetches taking 5-10s and 2.2% taking 2.5-5s. Root cause: 78 concurrent readers doing random mmap page faults across multi-GB data.bin files at 109M records. The I/O scheduler thrashes under this concurrency, inflating P99 to 2.5s (was 479ms at best steady-state).
Changes
crates/datasilo/src/lib.rs: Look up each key's offset in the hash index, sort by offset, read data.bin in sequential order, scatter results back to original positionssrc/server.rs: StaticLazyLock<Semaphore>with 16 permits acquired beforespawn_blocking— excess readers queue in async context instead of all faulting simultaneouslyTest plan
query_doc_disk_fetch_secondstail buckets (>500ms, >2.5s, >5s)bitdex_docstore_concurrent_readsgauge — should cap at ~16 instead of ~78🤖 Generated with Claude Code